<template>
  <div>
    <input v-model="searchName" placeholder="搜索姓名">
    <button @click="searchUser">搜索</button>

    <table>
      <tr>
        <th>姓名</th>
        <th>性别</th>
        <th>出生日期</th>
        <th>手机号</th>
        <th>邮箱</th>
      </tr>
      <tr v-for="user in users" :key="user.id">
        <td>{{ user.name }}</td>
        <td>{{ user.gender }}</td>
        <td>{{ user.birthDate }}</td>
        <td>{{ user.phone }}</td>
        <td>{{ user.email }}</td>
      </tr>
    </table>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      searchName: '',
      users: []
    };
  },
  methods: {
    searchUser() {
      axios.get(`/api/user/search`, { params: { name: this.searchName } })
          .then(response => {
            this.users = response.data;
          })
          .catch(error => {
            console.error(error);
          });
    }
  }
}
</script>
